package cn.sfrog.project.biz.web.controller;

import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.ApiAjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.project.biz.admin.service.IBizLiveRoomService;
import cn.sfrog.project.biz.web.vo.room.*;
import cn.sfrog.system.domain.vo.app.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/live")
@Api(value = "/api/live", tags = "APP直播相关")
public class AppLiveController extends BaseController {

    @Autowired
    private IBizLiveRoomService liveRoomService;

    @ApiOperation(value = "主播获取自己的房间信息")
    @GetMapping("/getMyLiveRoomInfo")
    public ApiAjaxResult<AppLiveRoomResultVO> getMyLiveRoomInfo() {
        AppLiveRoomResultVO myLiveRoomInfo = liveRoomService.getMyLiveRoomInfo();
        return ApiAjaxResult.success(myLiveRoomInfo);
    }



    @ApiOperation(value = "主播 开启直播")
    @PostMapping("/startLiveRoom")
    public ApiAjaxResult<AppLiveRoomResultVO> startLive(@RequestBody @Validated AppLiveRoomFormVO formVO) {
        AppLiveRoomResultVO liveRoom = liveRoomService.startLive(formVO);
        return ApiAjaxResult.success(liveRoom);
    }

    @ApiOperation(value = "主播 关闭直播")
    @PostMapping("/stopLiveRoom")
    public ApiAjaxResult stopLive() {
        return ApiAjaxResult.success(liveRoomService.stopLiveRoom());
    }


    @ApiOperation(value = "用户 获取直播列表")
    @GetMapping("/getLiveRoomList")
    public TableDataInfo<List<AppLiveRoomResultVO>> getLiveRoomList(AppLiveRoomQueryVO queryVO) {
        startPage();
        List<AppLiveRoomResultVO> bizLiveRoomVOS = liveRoomService.selectBizLiveRoomList4App(queryVO);

        return getDataTable(bizLiveRoomVOS);
    }


    @ApiOperation(value = "用户 获取房间详情")
    @GetMapping("/getLiveRoomInfo/{room_id}")
    public ApiAjaxResult<AppLiveRoomResultVO> getLiveRoomInfo(@PathVariable("room_id") Long roomId) {
        AppLiveRoomResultVO resultVO = liveRoomService.selectBizLiveRoomInfo(roomId);
        return ApiAjaxResult.success(resultVO);
    }


    @ApiOperation(value = "用户 预约直播")
    @PostMapping("/appointment")
    public ApiAjaxResult appointment(@RequestBody @Validated AppLiveRoomAppointmentVo appLiveRoomAppointmentVo) {
        return ApiAjaxResult.success(liveRoomService.appointment(appLiveRoomAppointmentVo));
    }


    @ApiOperation(value = "用户 进出直播间")
    @PostMapping("/inoutLiveRoom")
    public ApiAjaxResult inoutLiveRoom(@RequestBody @Validated AppLiveRoomJoinFormVO vo) {
        return ApiAjaxResult.success(liveRoomService.inoutLiveRoom(vo));
    }


    @ApiOperation(value = "用户 申请连麦")
    @PostMapping("/applyWheat")
    public ApiAjaxResult<List<TrtcStreamResultVO>> applyWheat(@RequestBody @Validated AppLiveRoomApplyWheatFormVO vo) {
        return ApiAjaxResult.success(liveRoomService.applyWheat(vo));
    }

    @ApiOperation(value = "主播 开始连麦")
    @PostMapping("/startWheat")
    public ApiAjaxResult startWheat(@RequestBody @Validated AppLiveRoomStartWheatFormVO vo) {
        return ApiAjaxResult.success(liveRoomService.startWheat(vo));
    }

//    @ApiOperation(value = "获取推拉流地址")
//    @PostMapping("/getTrtcStream")
//    public ApiAjaxResult<TrtcStreamResultVO> getTrtcStream() {
//        return ApiAjaxResult.success(liveRoomService.getTrtcStream());
//    }

}
